package com.corpgovernment.organization.convert;

import com.corpgovernment.api.organization.bo.RecManagerBO;
import com.corpgovernment.api.organization.model.backuser.BackgroundUserVo;
import com.corpgovernment.organization.entity.db.MbOrgEmployeeInfo;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jhxue
 * @create 2022-02-23-11:12
 */
@Component
public class EmployeeInfoConvert {

    public List<RecManagerBO> convertToRecManger(List<MbOrgEmployeeInfo> employeeInfos) {
        if (CollectionUtils.isEmpty(employeeInfos)) {
            return new ArrayList<>();
        }
        return employeeInfos.stream().map(e -> {
            RecManagerBO recManager = new RecManagerBO();
            recManager.setUid(e.getUid());
            recManager.setName(e.getName());
            recManager.setEmail(e.getEmail());
            return recManager;
        }).collect(Collectors.toList());
    }

    public static List<BackgroundUserVo> convertToBackgroundUser(List<MbOrgEmployeeInfo> employeeInfos) {
        if (CollectionUtils.isEmpty(employeeInfos)) {
            return Collections.emptyList();
        }
        return employeeInfos.stream().map(e -> {
            BackgroundUserVo backgroundUserVo = new BackgroundUserVo();
            backgroundUserVo.setId(e.getId());
            backgroundUserVo.setUid(e.getUid());
            backgroundUserVo.setName(e.getName());
            backgroundUserVo.setEmail(e.getEmail());
            backgroundUserVo.setAreaCode(e.getAreaCode());
            backgroundUserVo.setMobilePhone(e.getMobilePhone());
            backgroundUserVo.setGender(e.getGender());
            backgroundUserVo.setOrgId(e.getOrgId());
            backgroundUserVo.setOrgName(e.getOrgName());
            backgroundUserVo.setValid(e.getValid());
            return backgroundUserVo;
        }).collect(Collectors.toList());
    }
}
